package com.yanqu.road.utils.math;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author wpj
 * @Date 2020/9/21
 */
public class BuildCombine {
    int M;
    List<Integer> list;
    int[] b;

    List<List<Integer>> combineList = new ArrayList<>();

    public BuildCombine(List<Integer> list, int m) {
        int n = list.size();
        this.M = m;
        this.list = list;
        this.b = new int[m];
        C(n, m);
    }

    public void C(int n, int m) {
        int i, j;
        for (i = m; i <= n; i++) {
            b[m - 1] = i - 1;
            if (m > 1)
                C(i - 1, m - 1);
            else {
                List<Integer> l = new ArrayList<>();
                for (j = 0; j <= this.M - 1; j++)
                    l.add(this.list.get(b[j]));
                combineList.add(l);
            }
        }
    }

    public List<List<Integer>> getCombineList() {
        return combineList;
    }

    public void setCombineList(List<List<Integer>> combineList) {
        this.combineList = combineList;
    }
}
